import {axios} from "../utils/request";
import global from "../store/global";

const api = global.serverAddress + "/graph";

// 根据id获得一个知识图谱的详细信息，包括node和relation
export function getGraphDetailAPI(graphId) {
    return axios({
        url: `${api}/detail/${graphId}`,
        method: "GET"
    });
}

// 获得数据库中的所有Graph
export function getAllGraphAPI() {
    return axios({
        url: `${api}/get_all`,
        method: "GET"
    });
}

// 根据id精确查询Graph
export function getGraphByIdAPI(id) {
    return axios({
        url: `${api}/get_by_id/${id}`,
        method: "GET"
    });
}

// 根据name模糊查询Graph，同样不包含详细信息
export function getGraphByNameAPI(name) {
    return axios({
        url: `${api}/get_by_name/${name}`,
        method: "GET"
    });
}

// 根据name添加Graph
export function addGraphAPI(name) {
    return axios({
        url: `${api}/add/${name}`,
        method: "POST"
    });
}

// 根据id删除Graph
export function deleteGraphAPI(id) {
    return axios({
        url: `${api}/delete/${id}`,
        method: "POST"
    });
}

// 导出graphId所对应的知识图谱三元组的xml文件
export function exportGraphAsXmlAPI(graphId) {
    return axios({
        url: `${api}/export_graph_xml/${graphId}`,
        method: "POST"
    });
}

// 从csv三元组导入Graph
export function importGraphAPI(data) {
    return axios({
        url: `${api}/import_graph/${data.id}`,
        method: "POST",
        data: data.file
    });
}

// 根据id更新图谱
export function updateGraphAPI(graph) {
    console.log(graph);
    return axios({
        url: `${api}/update`,
        method: "POST",
        data: graph
    });
}

export function searchAPI(data) {
    return axios({
        url: `http://101.200.57.150:8001/search/${data.graphId}/${data.string}`,
        method: "GET"
    });
}